import { fileUpload } from '@/api/common/upload';
import { ElMessage, UploadProps, UploadRequestOptions } from 'element-plus';
export const beforeUploadHook = (rawFile:UploadProps['beforeUpload'], options: any) => {
  console.log('rawFile: ', rawFile);
  
  const {type,size} = options
  if (type.indexOf(rawFile.name.substring(rawFile.name.indexOf('\.')+1)) < 0) {
    ElMessage.error('上传文件格式不对,请上传'+type+'文件')
    return false
  } else if (rawFile.size / 1024 / 1024 > size) {
    ElMessage.error(`上传文件超过${size}MB!`)
    return false
  }
  return true
}

export const afterUploadHook:UploadProps['onSuccess'] = (resp,file,files) => {

}
export const httpUploadHook = (uploadOptions:UploadRequestOptions,options: Object,callback: Function) => {
  const payload = new FormData()
  payload.append('file',uploadOptions.file)
  console.log('payload: ', payload);
  fileUpload(payload).then((result) => {
    callback(result)
  });
}